package com.zzj.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzj.base.Result;
import com.zzj.entity.Inquiry;
import com.zzj.model.dto.QueryListDTO;
import com.zzj.model.dto.inquiry.InquiryCreateDTO;
import com.zzj.service.IInquiryService;
import com.zzj.utils.QueryUtil;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 快速问诊 前端控制器
 * </p>
 *
 * @author zzj
 * @since 2023-03-15
 */
@RestController
@RequestMapping("/inquiry")
public class InquiryController {


    @Resource
    private IInquiryService iInquiryService;


    @PostMapping("queryList")
    public Result queryList(@RequestBody @Validated QueryListDTO in){
        QueryWrapper<Inquiry> queryWrapper = QueryUtil.paramsWrapper(in.getAndParams(), in.getOrParams(), in.getOrderParams());
        Page<Inquiry> inquiryPage = new Page<>(in.getPageNo(), in.getPageSize());
        IPage<Inquiry> inquiryIPage = iInquiryService.getBaseMapper().selectPage(inquiryPage, queryWrapper);
        return Result.success(inquiryIPage);
    }
    /**
     * 患者用户快速问诊
     * @param in
     * @return
     */
    @PostMapping("create")
    public Result create(@RequestBody @Validated InquiryCreateDTO in){
        Inquiry inquiry = JSONObject.parseObject(JSON.toJSONString(in), Inquiry.class);
        iInquiryService.save(inquiry);
        return Result.success("提问成功");
    }
}
